require File.dirname(__FILE__) + '/ujs_helper'
require File.dirname(__FILE__) + '/tag_helper'
require 'action_view/helpers/url_helper'

module SimpleUjs
  module Helpers
    module UrlHelper
      include ActionView::Helpers::UrlHelper
      
      include SimpleUjs::Helpers::UrlHelper
      include SimpleUjs::Helpers::UjsHelper
      include SimpleUjs::Helpers::TagHelper
      
      alias_method :button_to_without_ujs, :button_to
      def button_to(name, options = {}, html_options = {})
        html_options = html_options.stringify_keys
        if should_use_ujs? &&
          (confirm = html_options.delete("confirm"))
            html_options[:onclick] = "if(#{confirm_javascript_function(confirm)}){this.form.submit();}"
        end
        button_to_without_ujs(name, options, html_options)
      end
      
      private
        alias_method :convert_options_to_javascript_without_ujs!, :convert_options_to_javascript!
        def convert_options_to_javascript!(html_options)
          return convert_options_to_javascript_without_ujs!(html_options) unless should_use_ujs?
          convert_options_to_ujs(html_options)

        end      
      
      
    end
  end
end